package co.fitstart.admin.dao;

import java.util.List;

import com.demo2do.core.persistence.annotation.Dynamic;
import com.demo2do.core.persistence.annotation.Limit;
import com.demo2do.core.persistence.annotation.Query;
import com.demo2do.core.persistence.annotation.Variable;

import co.fitstart.entity.coupon.Coupon;
import co.fitstart.entity.coupon.CouponBatch;
import co.fitstart.entity.coupon.CouponTemplate;
import co.fitstart.entity.coupon.stat.CouponTemplateStat;

/**
 * 
 * @author lidan
 *
 */
@Dynamic("hibernate")
public interface CouponDao {
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CouponTemplate WHERE disabled = false ORDER BY createTime DESC")
    public List<CouponTemplate> listCouponTemplate(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM CouponBatch WHERE credit = false ORDER BY createTime DESC")
    public List<CouponBatch> listCouponBatch(@Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param couponBatch
     * @param beginIndex
     * @param maxResult
     * @return
     */
    @Limit
    @Query("FROM Coupon WHERE batch = :batch ORDER BY id ASC")
    public List<Coupon> listCoupon(@Variable("batch") CouponBatch couponBatch, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    
    /**
     * 
     * @param code

     * @return
     */
    // @Limit
    // @Query("FROM Coupon WHERE batch = :batch ORDER BY id ASC")
    // public List<Coupon> listCoupon(@Variable("batch") CouponBatch couponBatch, @Variable("beginIndex") int beginIndex, @Variable("maxResult") int maxResult);
    @Query("FROM Coupon WHERE code like :code")
    public List<Coupon> list(@Variable("code") String code);
   



    /**
     * 
     * @param id
     * @return
     */
    @Query("FROM CouponTemplateStat couponTemplateStat WHERE couponTemplateStat.id = :id")
    public CouponTemplateStat getCouponTemplateStat(@Variable("id") Long id);
    
    /**
     * 
     * @param couponTemplate
     * @return
     */
    @Query("FROM CouponBatch WHERE couponTemplate = :couponTemplate")
    public CouponBatch getCouponBatch(@Variable("couponTemplate") CouponTemplate couponTemplate);
    
    @Query("FROM CouponBatch WHERE id = :id")
    public CouponBatch getCouponBatch(@Variable("id") Long id);
}
